package com.slw.emergency.schedule;

import com.slw.emergency.service.QueryService;
import com.slw.emergency.util.SpringUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class StaticScheduleTask {

    //定时任务:从接口获取数据,每天7点-23点，每隔1小时执行一次
    @Scheduled(cron = "0 0 7-23 * * ?")
    private void configureTasks() {
        System.err.println("执行获取疫情数据定时任务，开始时间: " + LocalDateTime.now());
        QueryService queryService = SpringUtil.getBean(QueryService.class);
        queryService.insertEpidemic();
        System.err.println("执行获取疫情数据定时任务，结束时间: " + LocalDateTime.now());
    }

    //定时更新小区信息
    @Scheduled(cron = "0 0 1 * * ?")
    private void configureAreaTasks() {
        System.err.println("获取小区信息定时任务，开始时间: " + LocalDateTime.now());
        QueryService queryService = SpringUtil.getBean(QueryService.class);
        queryService.insertDetail(true);
        System.err.println("获取小区信息定时任务，结束时间为: " + LocalDateTime.now());
    }
//    @Scheduled(cron = "0/5 * * * * ?")
//    private void configureTasks() {
//        System.err.println("执行静态定时任务时间: " + LocalDateTime.now());
//        QueryService queryService = SpringUtil.getBean(QueryService.class);
//        queryService.insertDetail(true);
//        System.err.println("结束时间为: " + LocalDateTime.now());
//    }

}
